const Nightmare = require('nightmare')
const nightmare = Nightmare()
nightmare
    .goto('https://www.zhihu.com/search?type=content&q=')
    // .type("input[title='Google 搜索']", 'ScrapingBee')
    // .click("input[value='Google 搜索']")
    // .wait('#rso > div:nth-child(1) > div > div > div.r > a')
    // .evaluate(
    //     () =>
    //         document.querySelector(
    //             '#rso > div:nth-child(1) > div > div > div.r > a'
    //         ).href
    // )
    .type("input#Popover2-toggle", '睡前消息')
    .click("button[aria-label='搜索']")
    .wait('#SearchMain')
    .evaluate(
        () => 
            Array.from(document.querySelectorAll('.SearchResult-Card .ContentItem-title')).map((el)=>{
                return el.innerText
            })
        
    )
    .end()
    .then((link) => {
        console.log('then:', link)
    })
    .catch((error) => {
        console.error('error:', error)
    })